<template>
  <a-card :bordered="false" class="card-area">
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="学生信息" key="1" forceRender>
        <stu-info ref="stuInfo"></stu-info>
      </a-tab-pane>
      <a-tab-pane tab="学籍信息" key="2" forceRender>
        <stu-status-info ref="stuStatusInfo" :xjxx="xjxx" />
      </a-tab-pane>
      <a-tab-pane tab="入学成绩" key="3">
        <scoreInfo ref="scoreInfo" :rxcj="rxcj"/>
      </a-tab-pane>
    </a-tabs>
    <div class="ant-pro-footer-toolbar">
      <div style="float: right;">
        <a-button style="margin-right: 10px;margin-right: 50px;" @click="reset">重置</a-button>
        <a-button style="margin-right: 10px;" @click="creatStu" type="primary">保存</a-button>
      </div>
    </div>
  </a-card>
</template>
<script>
// import { mapState } from 'vuex'
import stuInfo from './component/stuInfo'
import scoreInfo from './component/score'
import stuStatusInfo from './component/stuStatusInfo'
export default {
  data () {
    return {
      info: {},
      rxcj: {},
      xjxx: {},
      show: true
    }
  },
  components: {
    stuInfo,
    scoreInfo,
    stuStatusInfo
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  // mount () {
  //   this.xh = this.$route.query.xh
  //   this.$route.query.xh && this.$api.student.stuXjInfo(this.xh).then(res => {
  //     this.info = res.data
  //     console.log(res.data.xjxx)
  //     res.data.rxcj && (this.rxcj = res.data.rxcj)
  //     res.data.xjxx && (this.xjxx = res.data.xjxx)
  //     this.info.rxcj = undefined
  //     this.info.xjxx = undefined
  //     this.$changeDate(this.info)
  //     this.$changeDate(this.xjxx)
  //     this.$changeDate(this.rxcj)
  //     this.$refs.stuInfo.form.setFieldsValue(this.info)
  //     this.$refs.stuStatusInfo.form.setFieldsValue(this.xjxx)
  //     this.$refs.scoreInfo.form.setFieldsValue(this.rxcj)
  //   })
  // },
  methods: {
    creatStu () {
      let isComplete = true
      this.$refs.stuInfo.form.validateFields((err, values) => {
        this.$refs.stuInfo.$refs.stuInfo1.form.validateFields((err1) => {
          if (err1) {
            isComplete = false
            this.$message.error('请输入学生信息必填项')
            return
          }
        })
        if (err) {
          isComplete = false
          this.$message.error('请输入学生信息必填项')
          return
        }
      })
      this.$refs.stuStatusInfo.form.validateFields((err, values) => {
        if (err) {
          isComplete = false
          this.$message.error('请输入学籍信息必填项')
          return
        }
      })
      if(isComplete){
        const data = Object.assign({}, this.$refs.stuInfo.form.getFieldsValue(), this.$refs.stuInfo.$refs.stuInfo1.form.getFieldsValue())
        const rxcj = this.$refs.scoreInfo && this.$refs.scoreInfo.form.getFieldsValue()
        const xjxx = this.$refs.stuStatusInfo && this.$refs.stuStatusInfo.form.getFieldsValue()
        this.$DateToString(data)
        this.$DateToString(rxcj)
        this.$DateToString(xjxx)
        data.rxcj = rxcj
        data.xjxx = xjxx
        this.$api.student.stuAdd(data).then(res => {
          this.$message.success('保存成功')
        })
      }
    },
    reset () {
      this.$refs.stuInfo.form.resetFields()
      this.$refs.stuInfo.$refs.stuInfo1.form.resetFields()
      this.$refs.scoreInfo.form.resetFields()
      this.$refs.stuStatusInfo.form.resetFields()
    }
  }
}
</script>
